{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ced98145",
   "metadata": {},
   "source": [
    "# 上周回顾\n",
    "> 1."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e196bb6",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    ">1. 元组\n",
    ">2. 集合\n",
    ">3. 字典"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "136db33f",
   "metadata": {},
   "source": [
    "# 1.元组（tuple）\n",
    "\n",
    "> 1. 元组的基本内容（形态、定义）\n",
    "> 2. 元组的性质\n",
    ">> 1. 有序性\n",
    ">> 2. ***不可变性***(元组没有 增、删、改)\n",
    "> 3. 元组的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7b51f588",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(39838, 88308, 3819301) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "网二_学号=(39838,88308,3819301)\n",
    "print(网二_学号,type(网二_学号))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1511b319",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(39838, 88308, 3819301) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "网二_学号=39838,88308,3819301\n",
    "print(网二_学号,type(网二_学号))# 不用括号也属于元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8bf7c87e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "39838"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_学号[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "375f98f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(88308, 3819301)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_学号[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bc38d90d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(39838, 88308, 3819301)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_学号[0:]# :为到底"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2ddc2239",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=10, tm_mday=25, tm_hour=15, tm_min=7, tm_sec=15, tm_wday=1, tm_yday=298, tm_isdst=0)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 元组的实际案例\n",
    "import time\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "96c08ff3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "([1, 2, 3, 4], [3, 4, 5, 6]) <class 'tuple'> 2420853336000\n"
     ]
    }
   ],
   "source": [
    "tuple_test = ([1,2,3,4],[3,4,5,6])\n",
    "print(tuple_test,type(tuple_test),id(tuple_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "dad161d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "tuple_test[0].append(100) # 元组不可变，元组内的列表可以变\n",
    "# 一般情况下，元组内存放的是 常量（不可变：数字、字符串）\n",
    "# 不推荐存放 变量（如：列表、字典）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "baae5821",
   "metadata": {},
   "source": [
    "## 2.集合（sets）\n",
    ">1. 集合的基本概念\n",
    ">>1. 性质：没有重复项\n",
    ">>2. 性质：无序性\n",
    ">2. 集合的一般方法\n",
    ">>1. 集合的运算\n",
    ">>2. 一般运算方法（交集&  并集|）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "54e98fd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "戏剧社={1,2,3,4,5,6}\n",
    "表演部={2,7,1,3}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "4f6222ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "戏剧社&表演部# &表示相交的部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "6ff94de9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 2, 3, 4, 5, 6, 7}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "戏剧社|表演部# |表示并在一起的部分"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8fee5171",
   "metadata": {},
   "source": [
    "## 3.字典(dict)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de75b34f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 因为动物是唯一的，可以作为字典的key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "feb82e9d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1001: '狮子', 1002: '老虎', 1003: '意大利黑野猪', 1004: '法兰西大耗子', 1005: '黑龙江红长虫'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "动物园={\n",
    "    1001:\"狮子\",\n",
    "    1002:\"老虎\",\n",
    "    1003:\"意大利黑野猪\",\n",
    "    1004:\"法兰西大耗子\",\n",
    "    1005:\"黑龙江红长虫\"   \n",
    "}\n",
    "print(动物园,type(动物园))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6742ce5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
